<?php
import('Psg.Messages');
import('Psg.Core');
$messages = \Psg\Messages::getMessagesToUser(PSG_CURUSREUID);
?>
<h1>Skrzynka odbiorcza</h1>
<p class="notice">
    <a href="<?= Url::site('messages/outbox') ?>">Przejdź do skrzynki nadawczej</a>
</p>
<?php if (count($messages) == 0): ?>
    <p class="onlineTxt">Brak wiadomości w skrzynce odbiorczej</p>
<?php else: ?>
    <div class="tableDiv" style="width: 100%;">
        <div class="tableRow" style="height: 2.5em; font-weight: bold;">
            <div class="tableCell">Od</div>
            <div class="tableCell">Temat wiadomości</div>
            <div class="tableCell">Data wysłania</div>
        </div>
        <?php foreach ($messages as $id => $rowcol): ?>
            <div class="tableRow" style="<?= ($rowcol['unread'] == 1) ? 'font-weight:bold' : '' ?>">
                <div class="tableCell" style="height: 1.5em;">
                    <a href="<?= Url::site('overview/profile/' . $rowcol['from']) ?>">
                        <?= \Psg\Core::getUserInfo(\Psg\Core::getUserMailById($rowcol['from']))['nick'] ?>
                    </a>
                </div>
                <div class="tableCell">
                    <a href="<?= Url::site('messages/read/inbox/' . $rowcol['id']) ?>">
                        <?= $rowcol['topic'] ?>
                    </a>
                </div>
                <div class="tableCell"><?= \Psg\Core::timestampToWord($rowcol['time']) ?></div>
            </div>
        <?php endforeach; ?>
    </div>
<?php endif; ?>
